<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var fun = function (str) {
            var obj = {}
            for (let i = 0; i < str.length; i++) {
                var v = str.charAt(i);
                //将数组的i个元素作为obj对象的属性查看其属性值
                var counts = obj[v];
                //如果obj对象没有该属性，则设置该属性的值为1，有的话在其基础上再+1
                if (counts) {
                    obj[v] += 1;
                } else {
                    obj[v] = 1;
                }

            }
            console.log(obj)
        }("abcdacbabcbababcbabcabd")
    </script>
</body>

</html>